home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_09 / letters / tick1.cpp < prev    next >
C/C++ Source or Header  |  1995-07-17  |  3KB  |  149 lines

  1. //Listing 1: TICK1.CPP
  2.  
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <dos.h>
  6. #include <time.h>
  7.  
  8. #define RACK 1
  9.  
  10. #define ERR if (*err<0))   \
  11.    printf("\nError No. %d, \
  12.    Address No. %d,         \ 
  13.    Command No. %d", *err,  \
  14.    *add, *com);
  15.  
  16. int near *err; //ptr to error ret
  17. int near *add; //ptr to optomux adr
  18. int near *com; //ptr to optomux cmd
  19.  
  20. //pointers to module position in
  21. //optomux rack, modifier array, and
  22. //data return array:
  23. int near modu[16], modi[2], dat[l6];
  24.  
  25. //initialize rack and variables
  26. void ints(void);
  27.  
  28. //read inputs               
  29. void read_modules(void);
  30.  
  31. //call the driver
  32. extern "C" void pascal 
  33.   optoware(int near*, int near*, 
  34.            int near*, int near*, 
  35.            int near*, int near*); 
  36. // driver
  37. main()
  38. {
  39. int count = 0; //value of scans ctr
  40.  
  41. //clock ticks at current scan
  42. clock_t curr_time = 0;
  43.  
  44. //clock ticks at first scan
  45. clock_t start_time = 0;
  46.  
  47. clrscr();
  48. inits(); // ready sys for startup
  49.  
  50. //clock ticks at initial scan
  51. start_time = clock();
  52.  
  53. //loop through 5000 reads
  54. while (count < 5000 && !kbhit()){
  55.    read_size();
  56.    curr_time 
  57.      = clock(); // clk ticks now
  58.    count+= l; // clock ticks now
  59.    }
  60. clrscr();
  61. gotoxy(22, 2);
  62. printf(
  63. "Total ticks for 5000 reads..%ld", 
  64.    curr_time-start_time);
  65. if (kbhit())  // loop early exit
  66.    {
  67.    clrscr();
  68.    gotoxy(22, 10);
  69.    printf("Oops, you hit the ");
  70.    printf("boo boo bye bye key!");
  71.    gotoxy(1, 1)
  72.    }
  73. return 0; // end of function main
  74. }
  75.  
  76. /********************************/
  77. // ready system for operation
  78. void inits(void) 
  79. {
  80. int i; // array variable index
  81. //array variable index
  82. int er = 0, cmd = 102;
  83. int ad = 0; // host address
  84.  
  85. err= &er;
  86. add = &ad;
  87. com = &cmd;
  88. dat[0] = 3; // set host to com3
  89.  
  90. //call driver
  91. optoware(err, add, com, 
  92.          modu, modi, dat);
  93. ERR        // error macro
  94.  
  95. // set host baud rate to 38400
  96. cmd= 104;                    
  97. dat[0] = 38400;  
  98. optoware(err, add, com, 
  99.          modu, modi, dat);
  100. ERR
  101.  
  102. //initialize optoware parameters
  103. for (i=0; i<=15; ++i){       
  104.    modu[i] = 0;
  105.    dat[i] = 0;
  106.    }
  107.  
  108. modi[0] = 0;
  109. modi[1] = 0;
  110. //disable power-up clear msg.
  111. cmd = 0;
  112.  
  113. add = RACK; // for optomux rack
  114. er= 0;
  115. optoware(err, add, com, 
  116.          modu, modi, dat);
  117. ERR
  118.  
  119. return;
  120. }
  121. /****************************/
  122. void read_modules(void)  
  123. {
  124. int ad_size 
  125.   = RACK; // at address RACK
  126.  
  127. // 12 is command to read
  128. int s_cmd = 12;
  129.  
  130. // reset any previous errors
  131. int s_err = 0;             
  132.  
  133. // point globals to locals
  134. add = &ad_size;            
  135. com = &s_cmd;
  136. err = &s_err;
  137.  
  138. optoware(err, add, com, 
  139.          modu, modi, dat);
  140. ERR
  141.  
  142. // For anyone curious to know,
  143. // this program indicates about
  144. // 5.65 millisecond per scan
  145. return;
  146. }
  147.  
  148.  
  149.